﻿package II.controls {
	
	import flash.display.*;
	
	public class UIStackPanel extends UIBase {

		// CONSTANTS //
		
		public static const STACK_HORIZ:int = 0;
		public static const STACK_VERT:int = 1;
		
		// CONSTANTS //
		
		
		// PROPERTIES //
		
		public function get direction () : int {
			return _direction;
		}
		public function set direction ( value:int ) : void {
			_direction = value;
			this.updateLayout();
		}
		private var _direction:int = STACK_VERT;
		
		// PROPERTIES //
		
		
		
		
		public function UIStackPanel() {
			// constructor code
		}

		override public function updateLayout () : void {
			//this.updateLayoutAllChild();
			var dist:int = 0;
			for ( var cont:int = 0; cont<this.numChildren; cont++ ) {
				var child:UIBase = this.getChildAt(cont) as UIBase;
				if ( child == null ) continue;
				child.updateLayout();
				switch ( this.direction ) {
					case STACK_HORIZ:
						child.x = dist;
						child.y = 0;
						dist += child.size.width;
					break;
					case STACK_VERT:
						child.x = 0;
						child.y = dist;
						dist += child.size.height;
					break;
				}
			}			
			this.size = new Size ( this.width, this.height );
		}
		
	}
	
}
